<?php

namespace app\controller;

use app\BaseController;
use think\facade\View;
use think\facade\Db;

class Install extends BaseController
{
    static public function index()
    {
        if (file_exists("../install.lock")) {
            return "此程序已安装，无需重新安装；若要重装请删除./install.lock文件";
        } else {
            return View::fetch('admin/install');
        }
    }
    /*
    static public function write($a, $b, $c, $d)
    {
        if (file_exists("../install.lock")) {
            return json_encode(array("code" => 403, 'msg' => "此程序已安装，无需重新安装；若要重装请删除./install.lock文件"));
        } else {
            $content = "安装完毕";
            file_put_contents('../install.lock', $content);
        }
        return json_encode(array("code" => 200, 'msg' => '配置完毕'));
    }*/

    static public function install()
    {
        if (file_exists("../install.lock")) {
            return json(array("code" => 403));
        } else {
            Db::execute(file_get_contents('../app/controller/install.sql'));
            
            $content = "安装完毕";
            file_put_contents('../install.lock', $content);
            
            return json(array("code" => 200, 'msg' => '安装完毕'));
        }
    }
}
